package com.example.auto.demoforleothon.Presenter;

import android.os.Handler;

import com.example.auto.demoforleothon.Model.IuserBiz;
import com.example.auto.demoforleothon.Model.OnloginListener;
import com.example.auto.demoforleothon.Model.User;
import com.example.auto.demoforleothon.Model.UserBiz;
import com.example.auto.demoforleothon.View.IuserLogin;



public class UserLoginPresenter {

    private IuserBiz iuserBiz;
    private IuserLogin iuserLogin;

    private Handler handler=new Handler();

    public UserLoginPresenter(IuserLogin iuserLogin){
        this.iuserLogin=iuserLogin;
        this.iuserBiz=new UserBiz();
    }

    public void login(){
        iuserBiz.login(iuserLogin.getUsername(), iuserLogin.getPassword(), new OnloginListener() {
            @Override
            public void LoginSuccess(final User user) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        iuserLogin.toMainActivity(user);
                    }
                });
            }

            @Override
            public void LoginFailed() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        iuserLogin.showErrorInfo();
                    }
                });
            }
        });
    }
    public void clear(){
        iuserLogin.clearUsername();
        iuserLogin.clearPassword();
    }
}
